
import { Component, OnInit, Input, Output, EventEmitter,  OnDestroy, OnChanges, SimpleChanges } from '@angular/core';

@Component({
  selector: 'app-data-list',
  templateUrl: './data-list.component.html',
  styleUrls: ['./data-list.component.scss']
})
export class DataListComponent implements OnInit, OnChanges, OnDestroy {
  @Input() data = null;
  @Input() icon = './assets/img/search/pin_bg.png';
  @Output() searchListItemClick = new EventEmitter<any>();
  @Output() zoomto = new EventEmitter<any>();
  selectActive = -1;
  constructor( ) { }

  ngOnInit() {
  }
  itemClick(item, i) {
    this.selectActive = i;
    this.zoomto.emit(item);
  }
  ngOnChanges(changes: SimpleChanges) {
    if (changes.data && changes.data.currentValue) {
      // 排序
      this.data = changes.data.currentValue.sort( (a, b) => {
        return (a.mc).localeCompare(b.mc);
      });
    }
  }
  ngOnDestroy() {
    this.selectActive = -1;
  }

}
